﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Collections.Generic;
using QA_System.QASysDataSetTableAdapters;

namespace QA_System
{
    public class Painting
    {
        private static PAINTTableAdapter paintAdapter = new PAINTTableAdapter();

        public static QASysDataSet.PAINTDataTable GetAllPainting()
        {
            try
            {
                QASysDataSet.PAINTDataTable paintTable = paintAdapter.GetData();
                return paintTable;
            }
            catch (Exception ex)
            {
                throw ex;
            }            
        }

        public static Paintingfield GetByPaintingId(int paintingId)
        {
            try
            {
                QASysDataSet.PAINTDataTable paintTable = paintAdapter.GetDataByPaintId(paintingId);
                if (paintTable.Rows.Count == 0)
                    return null;
                else
                {
                    Paintingfield FData = new Paintingfield();
                    FData.Paint_ID = int.Parse(paintTable.Rows[0]["Paint_Id"].ToString());
                    FData.Own_ID = int.Parse(paintTable.Rows[0]["Own_Id"].ToString());
                    FData.Art_ID = int.Parse(paintTable.Rows[0]["Art_Id"].ToString());
                    FData.Gen_ID = int.Parse(paintTable.Rows[0]["Gen_Id"].ToString());
                    FData.Painting_Name = paintTable.Rows[0]["Name"].ToString();
                    FData.Height = float.Parse(paintTable.Rows[0]["Height"].ToString());
                    FData.Width = float.Parse(paintTable.Rows[0]["Width"].ToString());
                    FData.Material = paintTable.Rows[0]["Material"].ToString();

                    if (paintTable.Rows[0]["Year"].ToString() != "") FData.Painting_Year = paintTable.Rows[0]["Year"].ToString();
                    else FData.Painting_Year = "";
                    if (paintTable.Rows[0]["Price"].ToString() != "") FData.Price = double.Parse(paintTable.Rows[0]["Price"].ToString());
                    else FData.Price = -1;
                    if (paintTable.Rows[0]["Description"].ToString() != "") FData.Description = paintTable.Rows[0]["Description"].ToString();
                    else FData.Description = "";
                    return (FData);
                }
            }
            catch (Exception ex)
            {
                
                throw ex;
            }            
        }

        public static Paintingfield GetByPaintingName(string paintingName)
        {
            try
            {
                QASysDataSet.PAINTDataTable paintTable = new QASysDataSet.PAINTDataTable();
                paintTable = paintAdapter.GetDataByPaintingName(paintingName);
                if (paintTable.Rows.Count == 0)
                    return null;
                else
                {
                    Paintingfield FData = new Paintingfield();
                    FData.Paint_ID = int.Parse(paintTable.Rows[0]["Paint_Id"].ToString());
                    FData.Own_ID = int.Parse(paintTable.Rows[0]["Own_Id"].ToString());
                    FData.Art_ID = int.Parse(paintTable.Rows[0]["Art_Id"].ToString());
                    FData.Gen_ID = int.Parse(paintTable.Rows[0]["Gen_Id"].ToString());
                    FData.Painting_Name = paintTable.Rows[0]["Name"].ToString();
                    FData.Height = float.Parse(paintTable.Rows[0]["Height"].ToString());
                    FData.Width = float.Parse(paintTable.Rows[0]["Width"].ToString());
                    FData.Material = paintTable.Rows[0]["Material"].ToString();

                    if (paintTable.Rows[0]["Year"].ToString() != "") FData.Painting_Year = paintTable.Rows[0]["Year"].ToString();
                    else FData.Painting_Year = "";
                    if (paintTable.Rows[0]["Price"].ToString() != "") FData.Price = double.Parse(paintTable.Rows[0]["Price"].ToString());
                    else FData.Price = -1;
                    if (paintTable.Rows[0]["Description"].ToString() != "") FData.Description = paintTable.Rows[0]["Description"].ToString();
                    else FData.Description = "";
                    return (FData);
                } 
            }
            catch (Exception ex)
            {
                throw ex;
            }            
        }

        public static QASysDataSet.PAINTDataTable GetAllByArtist(int artistId)
        {
            try
            {
                QASysDataSet.PAINTDataTable paintingTable = paintAdapter.GetDataByArtistId(artistId);
                return paintingTable;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static QASysDataSet.PAINTDataTable GetAlldataByGenre(int genreId)
        {
            try
            {
                QASysDataSet.PAINTDataTable paintingTable = paintAdapter.GetDataByGenreId(genreId);
                return paintingTable;
            }
            catch (Exception ex)
            {
                throw ex;
            }            
        }

        public static QASysDataSet.PAINTDataTable GetAllByMaterial(string material)
        {
            try
            {
                QASysDataSet.PAINTDataTable paintingTable = paintAdapter.GetDataByMaterial(material);
                return paintingTable;  
            }
            catch (Exception ex)
            {
                throw ex;
            }                      
        }

        public static string GetAllMaterial()
        {
            try
            {
                QASysDataSet.PAINTDataTable paintingTable = paintAdapter.GetData();
                List<string> _material = new List<string>();
                foreach (var row in paintingTable)
                {
                    _material.Add(row.Material);
                }
                string temp = "";
                foreach (var item in _material.Distinct())
                {
                    temp += item + "/";
                }
                return temp;
            }
            catch (Exception ex)
            {                
                throw ex;
            }            
        }

        public static QASysDataSet.PAINTDataTable GetAllByOwnerId(int ownerId)
        {
            try
            {
                QASysDataSet.PAINTDataTable paintTable = paintAdapter.GetDataByOwnerId(ownerId);
                return paintTable;
            }
            catch (Exception ex)
            {
                throw ex;
            }            
        }

        public static string GetAllPaintName()
        {
            try
            {
                QASysDataSet.PAINTDataTable paintingTable = paintAdapter.GetData();
                string temp = "";
                if (paintingTable.Rows.Count != 0)
                {
                    for (int i = 0; i < paintingTable.Rows.Count; i++)
                        temp += paintingTable.Rows[i]["Name"].ToString() + "/";
                }
                return temp;
            }
            catch (Exception ex)
            {                
                throw ex;
            }            
        }
    }
}